//
//  YRWelcomeViewController.swift
//  新浪微博
//
//  Created by Viper on 16/6/27.
//  Copyright © 2016年 Viper. All rights reserved.
//

import UIKit
import SDWebImage
class YRWelcomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupUI()
        
    }
    
    override func loadView() {
        view = bgImageView
    }
    
    override func viewDidAppear(animated: Bool) {
        
        super.viewDidAppear(animated)
        
        self.headImageView.snp_updateConstraints { (make) in
            
            make.top.equalTo(self.view).offset(100)
            
        }
        
        UIView.animateWithDuration(2, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: {
            
            self.view.layoutIfNeeded()
            
            }) { (_) in
                UIView.animateWithDuration(0.5, animations: {
                    
                    self.messageLabel.alpha = 1
                    
                    }, completion: { (_) in
                        //当前界面的动画完成  改变跟控制器  变成MainVC
                        //发送通知
                        NSNotificationCenter.defaultCenter().postNotificationName(SwitchRootVcNoti, object: "welcome")
                        
                })
        }
    }

     // MARK: - 设置视图
    private func setupUI(){
    
        view.addSubview(messageLabel)
        view.addSubview(headImageView)
        
        
        headImageView.snp_makeConstraints { (make) in
            
            make.top.equalTo(view).offset(400)
            make.size.equalTo(CGSize(width: 90, height: 90))
            make.centerX.equalTo(view)
        }
        
        messageLabel.snp_makeConstraints { (make) in
            
            make.top.equalTo(headImageView.snp_bottom).offset(16)
            make.centerX.equalTo(view)
        }
    
    }
     // MARK: - 懒加载
    private lazy var bgImageView = UIImageView(imageName: "ad_background")
    private lazy var headImageView :UIImageView = {
       
        let imageView = UIImageView(image: UIImage(named: "avatar_default_big"))
        imageView.layer.cornerRadius = 45
        imageView.layer.masksToBounds = true
        imageView.layer.borderColor = ThemeColor.CGColor
        imageView.layer.borderWidth = 3
        //设置图片
        imageView.sd_setImageWithURL(NSURL(string:YRUserAccountTools.sharedTools.userAccount?.avatar_large ?? ""), placeholderImage: UIImage(named: "ad_background"))
        
        return imageView
    }()
    private lazy var messageLabel : UILabel = {
        
        let label = UILabel ()
        
        label.font = UIFont.systemFontOfSize(20)
        label.text = "欢迎回来"
        label.textAlignment = .Center
        label.textColor = UIColor.grayColor()
        label.alpha = 0
        
        return label
        
    }()
    
}
